package com.example.demo.mapper;

import com.example.demo.bean.KafkaLog;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface KafkaLogMapper {
    @Insert("insert into kafka_log(topic,messageId,messageBody,num,send) " +
            "values(#{topic},#{messageId},#{messageBody},#{num},#{send})")
    int add(KafkaLog kafkaLog);

    @Update("update kafka_log set status=#{status} where messageId=#{messageId}")
    int update(@Param("messageId") String messageId, @Param("status") String status);

    @Update("update kafka_log set num=num+1,status=#{status} where messageId=#{messageId}")
    int updateNumAndStatus(@Param("messageId") String messageId, @Param("status") String status);

    @Update("update kafka_log set send=#{send} where messageId=#{messageId}")
    int updateSendFlag(@Param("messageId") String messageId, @Param("send") String send);

    @Select("select * from kafka_log where status='2' or status='3'")
    List<KafkaLog> queryKafkaLogFailByStatus();

    @Select("select * from kafka_log where (status='0' or status='1') and updateTime < date_sub(now(),INTERVAL 1 hour)")
    List<KafkaLog> queryKafkaLogFailByTimeout();

    @Select("select * from kafka_log where messageId=#{messageId}")
    KafkaLog queryKafkaLogByMessageId(@Param("messageId") String messageId);
}
